package com.hbnu.iostream;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

/**
 * 需求：使用打印流往指定文件中输出内容
 *
 * @author kittychen
 * @since 2025-10-11 下午 3:46
 */
public class PrinterStreamDemo {
    public static void main(String[] args) {
        String path = "E:" + File.separator + "2310" + File.separator + "priter.txt";
        File file = new File(path);

        PrintStream ps = null;

        try {
            ps = new PrintStream(new FileOutputStream(file, true));
            ps.println("hello world");
            ps.println("hello kitty");
            ps.println("1+1=" + 2);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (ps != null) {
                ps.close();
            }
        }
    }
}
